/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package swingDemoEvent;

/**
 *
 * @author Administrator
 */
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class CheckBoxTest {

    public static void main(String[] args) {
        CheckBoxFrame frame = new CheckBoxFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }
}

class CheckBoxFrame extends JFrame implements ItemListener {
    public static final int DEFAULT_WIDTH = 300;
    public static final int DEFAULT_HEIGHT = 200;
    private JLabel label;
    private JCheckBox bold;
    private JCheckBox italic;
    private static final int FONTSIZE = 12;
    public CheckBoxFrame() {
        setTitle("CheckBoxTest");
        setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
        label = new JLabel(
                "The quick brown fox jumps over the lazy dog.");
        label.setFont(new Font("Serif", Font.PLAIN, FONTSIZE));
        add(label, BorderLayout.NORTH);
        JPanel buttonPanel = new JPanel();
        bold = new JCheckBox("Bold");
        bold.addItemListener(this);
        buttonPanel.add(bold);
        italic = new JCheckBox("Italic");
        italic.addItemListener(this);
        buttonPanel.add(italic);
        add(buttonPanel, BorderLayout.SOUTH);
    }
    @Override
    public void itemStateChanged(ItemEvent e) {
        {
            int mode = 0;
            if (bold.isSelected()) {
                mode += Font.BOLD;
            }
            if (italic.isSelected()) {
                mode += Font.ITALIC;
            }
            label.setFont(new Font("Serif", mode, FONTSIZE));
        }
    }
;
}
